package com.acwing.partition11;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 * @author `RKC`
 * @date 2021/12/25 16:27
 */
public class AC1085不要62 {

    private static final int N = 11;
    private static final int[][] dp = new int[10][N];

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        init();
        while (true) {
            String[] s = reader.readLine().split("\\s+");
            int x = Integer.parseInt(s[0]), y = Integer.parseInt(s[1]);
            if (x == 0 && y == 0) break;
            writer.write((resolve(y) - resolve(x - 1)) + "\n");
        }
        writer.flush();
    }

    private static void init() {
        //当位数只有1位的时候，只有4不能取
        for (int i = 0; i <= 9; i++) dp[i][1] = i == 4 ? 0 : 1;
        //位数有多位的时候，额外需要考虑当前为i和下一位j是否会构成62的情况
        for (int length = 2; length < N; length++) {
            for (int i = 0; i <= 9; i++) {
                if (i == 4) continue;
                for (int j = 0; j <= 9; j++) {
                    if (j == 4 || (i == 6 && j == 2)) continue;
                    dp[i][length] += dp[j][length - 1];
                }
            }
        }
    }

    private static int resolve(int num) {
        if (num == 0) return 1;
        List<Integer> nums = new ArrayList<>();
        while (num != 0) {
            nums.add(num % 10);
            num /= 10;
        }
        //这里的last保存当前遍历的数的上一位
        int answer = 0, last = 0;
        for (int i = nums.size() - 1; i >= 0; i--) {
            int x = nums.get(i);
            for (int j = 0; j < x; j++) {
                if ((j == 2 && last == 6) || j == 4) continue;
                answer += dp[j][i + 1];
            }
            //分支不合法，直接break
            if (x == 4 || (last == 6 && x == 2)) break;
            last = x;
            if (i == 0) answer++;
        }
        return answer;
    }
}
